<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>联动</title>
</head>
<body>
<div id="demo">
  姓：<input type="text" placeholder="First Name" v-model="firstName"><br>
  名：<input type="text" placeholder="Last Name" v-model="lastName"><br>
  姓名1(单向)：<input type="text" placeholder="Full Name1" v-model="FullName1"><br>
  姓名2(单向)：<input type="text" placeholder="Full Name2" v-model="FullName2"><br>
  姓名3(双向)：<input type="text" placeholder="Full Name3" v-model="FullName3"><br>
  <p>{{FullName1}}</p>
  <p>{{FullName1}}</p>
  <p>{{FullName1}}</p>

  <p>{{FullName2}}</p>
  <p>{{FullName2}}</p>
  <p>{{FullName2}}</p>

  <p>{{FullName3}}</p>
  <p>{{FullName3}}</p>
  <p>{{FullName3}}</p>
  </div>
  <script type="text/javascript" src="/js/vue.js"></script>
  <script type="text/javascript">
    Vue.config.productionTip = false//全局配置,关闭是开发还是生产环境提示,默认是true提示
    const vm = new Vue({
    el:'#demo',
    data(){
      return{
        firstName:'',
        lastName:'',
        // FullName1:'A-B'
        FullName2:''
      }
    },
    //计算属性
    computed: {
      /* 
      计算属性的方法什么执行
      1.初始显示执行一次
      2.依赖数据发生变化
       */
      FullName1(){//相当于只有get
        console.log('fullName1()');
        return this.firstName + '-' + this.lastName
      },
      FullName3:{
        get(){
          console.log('fullName3 get()')
          return this.firstName + '-' +this.lastName
        } ,

        set(value){//监视
          console.log('fullName3 set()',value)
          const names = value.split('-')
          this.firstName = names[0]
          this.lastName = names[1]
        }
      }
    },
    //监视
    watch: {
      firstName (value){//当firstName 发生了改变是调用
        //更新FullName2
        console.log('FullName2()',value)
        this.FullName2 = value + '-' + this.lastName
      }
    },
  })
   //监视lastName
    vm.$watch('lastName' ,function (value) {//相当于lastName发生了改变时候调用
      //更新fullName2
      console.log('lastName()',value)
      this.FullName2 = this.firstName + '-' + value
    
      
    })
  </script>
</body>
</html>